package com.example.fileoperate.readfile;/*
 * @Auther:hantianbing
 * @Date:2023/7/26
 * @Description:
 */

import com.example.fileoperate.exception.FailCause;
import com.example.fileoperate.exception.MyException;
import com.example.fileoperate.exception.ReadFileExceptoin;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName ReadFile
 * @Description
 * @Author hantianbing
 * @Date 2023/7/26 18:06
 **/
public class ReadFile {
    public static File readFileByPath(String path){
        File file = new File(path);
        if(file == null){
            throw new MyException(ReadFileExceptoin.FILE_NOT_EXIST);
        }
        //必须是文件类型
        if (file.isDirectory()) {
            throw new MyException(ReadFileExceptoin.FILE_TYPE_WRONG);
        }
        return file;
    }

    public static List<File> readFilesOneLevelByDir(String dir){
        File folder = new File(dir);
        if(folder == null){
            throw new MyException(ReadFileExceptoin.FILE_NOT_EXIST);
        }
        if(folder.isFile()){
            throw new MyException(ReadFileExceptoin.FILE_TYPE_WRONG);
        }
        return Arrays.asList(folder.listFiles());
    }

    public static List<File> readFilesEveryLevelByDir(String dir){
        return null;
    }
}
